function changeCountMavro(oper_id)
{
	var f = document.getElementById('f');
	if(oper_id != null && opers[oper_id])
	{
		var o = opers[oper_id];
		f.mavro_summ.value = o.ostatok;
	}
}

function countSumm()
{
	var f = document.getElementById('f');
	f.subm.disabled = true;
	var kurs = '';
	var mavro_summ = getNumber(f.mavro_summ.value);
	var summ = '';
	var summ_valuta = '';
	var y = Number(f.year.value);
	var m = Number(f.month.value);
	var d = Number(f.day.value);
	var oper_id = getSaleOperId();
	if(oper_id != null && opers[oper_id])
	{
		var oper_sale = opers[oper_id];
		var use_kurs_buy = oper_sale && oper_sale.id && f.use_kurs_sale_buy.checked;
		var type_kurs = use_kurs_buy ? 'buy' : 'sell';
		var date = use_kurs_buy ? oper_sale.date : y + "-" + m + '-' + d;
		kurs = _getKursByDate(date, oper_sale['percent'], type_kurs);
		if(kurs && mavro_summ > 0)
		{
			summ = mavro_summ * kurs;
			var kurs_valuta = use_kurs_buy ? oper_sale.kurs_valuta : 1;
			if(kurs_valuta == 0) kurs_valuta = 1;
			summ = (Math.round(summ * 10000 / kurs_valuta)) / 10000;
			summ_valuta = use_kurs_buy ? oper_sale.valuta : oper_sale.mavro_valuta;
			f.subm.disabled = false;
			for(var i = 0; i < f.valuta.options.length; i++)
			{
				if(f.valuta.options[i].value == summ_valuta)
				{
					f.valuta.selectedIndex = i;
				}
			}
		}
	}
	f.kurssale.value = kurs ? kurs : '';
	f.summ.value = summ + " " + summ_valuta;
	f.summ_buy.value = summ;
}

function checkMavroSumm()
{
	var f = document.getElementById('f');
	var oper_id = getSaleOperId();
	if(oper_id != null && opers[oper_id])
	{
		var o = opers[oper_id];
		if(getNumber(f.mavro_summ.value) > o.ostatok)
		{
			alert('Количество продаваемых мавро не должно превышать остаток по вкладу');
			f.mavro_summ.value = o.ostatok;
		}
	}
}

